<template>
  <div class="login-phone">
    <el-form label-width="65px" :rules="rules" :model="phone" ref="phoneref">
      <el-form-item label="手机号" prop="name">
        <el-input v-model="phone.name" />
      </el-form-item>
      <el-form-item label="验证码" prop="code">
        <div class="get-code">
          <el-input v-model="phone.code" type="code" />
          <el-button type="primary" class="get-botton-code"
            >获取验证码</el-button
          >
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { rules } from '../config/phone-config'
import { ElForm } from 'element-plus'
import { useStore } from 'vuex'

export default defineComponent({
  setup() {
    const phone = reactive({
      name: '',
      code: ''
    })
    const store = useStore()

    const phoneref = ref<InstanceType<typeof ElForm>>()
    const phoneactive = () => {
      phoneref.value?.validate((valid) => {
        if (valid) {
          store.dispatch('loginModule/phoneLoginAction', { ...phone })
        }
      })
    }

    return {
      phone,
      rules,
      phoneref,
      phoneactive
    }
  }
})
</script>

<style scoped lang="less">
.get-code {
  display: flex;
}
.get-botton-code {
  margin-left: 8px;
}
</style>
